def ihi(nu):
    for x in range(2, nu):
        if nu % x == 0:
            return False
    return True


prre = [x for x in range(10, 10000) if ihi(x)]
slo = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9,
}
stro = input().split()
try:
    line = slo[stro[0]] * 100 + slo[stro[1]] * 10 + slo[stro[2]]
    rast = 1000
    zapppure = 0
    for elem in prre:
        if abs(elem - line) < rast:
            rast = abs(elem - line)
            zapppure = elem
    print(zapppure)
except:
    print("Wrong input")